﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GShare1._0.Server
{
    public partial class GUI_FileDownload : Form
    {
        public GUI_FileDownload()
        {
            InitializeComponent();
        }

        private void GUI_FileUpload_FormClosed(object sender, FormClosedEventArgs e)
        {

        }

        /// <summary>
        /// Designed To be Called using a stopwatch tick event
        /// </summary>
        public void UpdateUI(float percent,int size,string user = null)
        {
            MethodInvoker updateMethod = new MethodInvoker(delegate
                {
                    if (user != null)
                    {
                        label4.Text = user;
                    }
                    progressBar1.Value = (int)percent;
                    label5.Text = size.ToString() + "bytes";

                    if (percent == 100)
                    {
                        //label6.Text = "Completed";
                        if (user != null)
                        {
                            MessageBox.Show("Completed Upload From: " + user);
                        }
                        else
                        {

                        }
                        this.Close();
                    }
                    
                });
            //label6.Text = download.percent.

            if (this.Visible)
            {
                this.BeginInvoke(updateMethod);
            }
            
            

        }

        private void GUI_FileUpload_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// Close the form Cross Thread
        /// </summary>
        public void CrossThreadClose()
        {
            MethodInvoker updateMethod = new MethodInvoker(delegate
                {
                    this.Close();
                });
            this.BeginInvoke(updateMethod);
        }
    }
}
